package dice.sinanya.tools.checkdata;

import dice.sinanya.db.monsterlist.SelectMonsterList;
import dice.sinanya.db.npclist.SelectNpcList;

import java.util.HashMap;

import static dice.sinanya.system.NpcListCache.MONSTER_LIST;
import static dice.sinanya.system.NpcListCache.NPC_LIST;

public class CheckList {

    public static boolean checkMonster(String groupId) {
        if (MONSTER_LIST.getOrDefault(groupId, new HashMap<>()).size() != 0) {
            return true;
        } else {
            new SelectMonsterList().selectMonsterListFromDatabase(groupId);
            return MONSTER_LIST.getOrDefault(groupId, new HashMap<>()).size() != 0;
        }
    }

    public static boolean checkMonsterName(String groupId, String name) {
        if (MONSTER_LIST.getOrDefault(groupId, new HashMap<>()).containsKey(name)) {
            return true;
        } else {
            new SelectMonsterList().selectMonsterListFromDatabase(groupId);
            return MONSTER_LIST.getOrDefault(groupId, new HashMap<>()).containsKey(name);
        }
    }

    public static boolean checkNpc(String groupId) {
        if (NPC_LIST.getOrDefault(groupId, new HashMap<>()).size() != 0) {
            return true;
        } else {
            new SelectNpcList().selectNpcListFromDatabase(groupId);
            return NPC_LIST.getOrDefault(groupId, new HashMap<>()).size() != 0;
        }
    }

    public static boolean checkNpcName(String groupId, String name) {
        if (NPC_LIST.getOrDefault(groupId, new HashMap<>()).containsKey(name)) {
            return true;
        } else {
            new SelectNpcList().selectNpcListFromDatabase(groupId);
            return NPC_LIST.getOrDefault(groupId, new HashMap<>()).containsKey(name);
        }
    }
}
